var token = localStorage['x-header-token'];
if (!token) {
    var loginModal = $('#login-modal');
    loginModal.modal({
        show: true,
        backdrop: 'static',
        keyboard: false
    });
    $('#login-btn').click(function () {
        var username = $('#username').val();
        var password = $('#password').val();
        if (!username) {
            $('#long-message').hide().html('<label class="label label-danger">Username can not be empty.</label>').show(300);
            return;
        }
        if (!password) {
            $('#long-message').hide().html('<label class="label label-danger">Password can not be empty.</label>').show(300);
            return;
        }

        $.ajax({
            url: "login",
            type: 'POST',
            contentType: 'application/json',
            data: JSON.stringify({username: username, password: password, "clientId":"JOB"}),
            success: function (result) {
                if (result.data) {
                    localStorage['x-header-token'] = result.data.access_token;
                    window.location.reload();
                } else {

                }
            }
        });
    });
}
$('#logout-btn').click(function () {
    localStorage.removeItem('x-header-token');
    window.location.reload();
});